import {View, ScrollView, Text} from "@tarojs/components";
import Utils from "@/utils/common";
import {Cell, Empty} from "@antmjs/vantui";
import RouthPath from "@/common/RouthPath";
import {useEffect, useRef, useState} from "react";
import {orderListById} from "@/common/apis/home_datasource";
import {MachineModel, OrderItem} from "@/common/apis/model";
import NumberUtils from "@/utils/number_utils";

definePageConfig({
  navigationBarTitleText: '预约情况'
})

export default function MachineOrderList() {
  const [machines, setMachines] = useState<OrderItem[]>()

  const machine = useRef<MachineModel>();
  useEffect(() => {
    const params = Utils.getParamsByRouter(Utils.getI())
    if (params && params.data) {
      machine.current = Utils.getObjectWithUrl<MachineModel>(params.data)
      orderListById(machine.current!.id).then((res) => {
        setMachines(res)
      })
    }
  }, []);
  return (
    <View
      style={{
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
        width: '100%',
        height: '100VH',
        boxSizing: 'border-box',
        padding: '10px',
      }}
    >

      <Cell title={machine.current?.name} />

      <ScrollView scrollY style={{height: '100%'}}>
        {
          !Utils.isEmpty(machines) ? machines!.map((item, index) => (<Cell key={index}
            renderTitle={<Text
              style={{marginLeft: '20px'}}
            >{`${item.contacts}(${item.phone})`}</Text>}
            renderLabel={<Text style={{
                                                            marginLeft: '20px',
                                                            color: 'green'
                                                          }}
            >{`样品数量：${NumberUtils.stringToFloat(item.bookTotalTime)}`}</Text>}
            renderIcon={item.id} isLink onClick={() => {
            Utils.navigateTo({
              url: Utils.getUrlWithObject(RouthPath.orderDetail, {id: item.id})
            })
          }}
          />)) : <Empty description='暂无预约' />
        }
      </ScrollView>
    </View>
  )

}


